Skip to content

Optimize hash_table_locks #618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Optimize hash_table_locks #618

wants to merge 1 commit into from

Conversation

wjunLu
Copy link

@wjunLu wjunLu commented Jul 22, 2025

Analysis

Under high throughput, a hotspot caused by rw_lock_s_lock_func can be observed in MySQL, originating from Buf_fetch_normal::get. The key call path is: buf_page_get_gen → Buf_fetch::single_page → Buf_fetch_normal::get.

The function of Buf_fetch_normal::get is to retrieve the pointer to a data block (i.e., buf_block_t*) in the buffer pool for a target data page, which involves querying the buffer pool using (space_id, page_no) to read or write page content. This mapping relationship is maintained by a hash table called page_hash, protected by hash_table_locks. The rw_lock_s_lock_func hotspot arises from the read-lock operation on these hash_table_locks.
image

On the other hand, sharding the lock objects with fierce competition is a common optimization method. In MySQL source code, hash_table_locks has been optimized through sharding. The number of shards is controlled by srv_n_page_hash_locks, but it is hard-coded to 16.
image

Optimization

hash

@wjunLu wjunLu changed the title Optimize hash table locks Optimize hash_table_locks Jul 22, 2025
@mysql-oca-bot
Copy link

Hi, thank you for submitting this pull request. In order to consider your code we need you to sign the Oracle Contribution Agreement (OCA). Please review the details and follow the instructions at https://oca.opensource.oracle.com/
Please make sure to include your MySQL bug system user (email) in the returned form.
Thanks

@wjunLu
Copy link
Author

wjunLu commented Jul 26, 2025

I have submitted the Oracle Contributor Agreement (OCA), it's under review now, but I have no idea when this can be approved

@wjunLu
Copy link
Author

wjunLu commented Aug 18, 2025

Hi, @ALL!
My OCA has been approved, could anyone help review this PR?
image

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment:
"I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it."
Thanks

@wjunLu
Copy link
Author

wjunLu commented Aug 18, 2025

I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow
bug http://bugs.mysql.com/bug.php?id=118866 for updates.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants